//
//  JZHDetailsSetViewController.m
//  极致荟
//
//  Created by hetao on 14-5-15.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "JZHDetailsSetViewController.h"
#import "JZHNoteViewController.h"
#import "JZHMyNameUpViewController.h"
#import "OtherUsersDao.h"
@interface JZHDetailsSetViewController ()
@property (weak, nonatomic) IBOutlet UISwitch *swith;

@end

@implementation JZHDetailsSetViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (id)initOuser:(OtherUsers *)ouser
{
    JZHDetailsSetViewController *jzh=[[JZHDetailsSetViewController alloc] init];
    jzh.ouser=ouser;
    return jzh;
}

- (IBAction)dorp:(id)sender
{
    [[[UIAlertView alloc] initWithTitle:@"提示" message:@"要把该好友从通讯录中移除吗？" delegate:self  cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil] show];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    if(OSVersionIsAtLeastiOS7>=7.0)
    {
        self.automaticallyAdjustsScrollViewInsets=NO;
    }    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 12, 20)];
    [leftButton addTarget:self action:@selector(leftDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    if(self.ouser.isAs)
    {
        self.swith.on=YES;
    }else{
        self.swith.on=NO;
    }
    self.navigationItem.leftBarButtonItem = leftBarButton;
    self.navigationItem.title=@"资料设置";

}
- (IBAction)pusbnaem:(id)sender
{
    [self presentViewController:[[JZHMyNameUpViewController alloc] initUserType:self.ouser] animated:YES completion:^{
        
    }];
   
}
- (IBAction)pusNoet:(id)sender {
    [self.navigationController pushViewController:[[JZHNoteViewController alloc]initOuser:self.ouser] animated:YES];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex==1)
    {
        NSDictionary *dic=[[NSDictionary alloc]initWithObjectsAndKeys:[NSNumber numberWithInt:[User defuceUser].userId],@"userId",[NSNumber numberWithInt:self.ouser.userId],@"friendId", nil];
        [HttpRequest httpRequestPost:JZHHTTPURL(@"friends/delFriend") parameters:dic block:^(id data, HttpReturnCode rerurncode) {
            NSLog(@"%@",data);
            [OtherUsersDao dorpData:self.ouser];
            [self.navigationController popToRootViewControllerAnimated:YES];
        }];
    }
}

- (void)leftDrawerButtonPress:(UIButton *)but
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)xinbiao:(UISwitch *)sender
{
    NSDictionary *dic=[[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:[User defuceUser].userId],@"userId",[NSNumber numberWithInt:self.ouser.userId],@"friendsId", nil];
   if(sender.on)
   {
       self.ouser.isAs=YES;
   }else
   {
       self.ouser.isAs=NO;
   }
    
    [HttpRequest httpRequestPost:JZHHTTPURL(@"asterisk/addAsterisk") parameters:dic block:^(id data, HttpReturnCode rerurncode) {
        
    }];
    [OtherUsersDao insertData:self.ouser];
}

@end
